package com.wx.mall.order.controller;


import com.wx.mall.common.api.CommonPage;
import com.wx.mall.common.api.CommonResult;
import com.wx.mall.common.api.ResultCode;
import com.wx.mall.common.exceptions.ApiAssert;
import com.wx.mall.order.dto.ReOrderDto;
import com.wx.mall.order.entity.ReturnCause;
import com.wx.mall.order.entity.ReturnOrder;
import com.wx.mall.order.service.impl.ReturnOrderServiceImpl;
import com.wx.mall.order.vo.GoodReturnItemVo;
import com.wx.mall.order.vo.GoodReturnVo;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 退款订单 前端控制器
 * </p>
 *
 * @author j
 * @since 2020-04-22
 */
@RestController
@RequestMapping("/return/order")
public class ReturnOrderController {

    @Autowired
    ReturnOrderServiceImpl returnOrderService;

    @ApiOperation(value = "分页查询")
    @GetMapping("/getPages")
    public CommonResult<CommonPage<ReturnOrder>> getPageList(ReOrderDto dto){
        if (dto.getPageNum() == null || dto.getPageSize() == null){
            ApiAssert.fail(ResultCode.VALIDATE_FAILED);
        }
        if (dto.getPageNum() == 0){
            ApiAssert.fail("无效页码");
        }
        List<ReturnOrder> returnCauseList=returnOrderService.finds(dto);
        return CommonResult.success(CommonPage.restPage(returnCauseList));
    }

    @ApiOperation(value = "筛选查询")
    @GetMapping("/getPageList")
    public CommonResult<CommonPage<ReturnOrder>> getListByOrder(ReOrderDto dto){
        if (dto.getPageNum() == null || dto.getPageSize() == null){
            ApiAssert.fail(ResultCode.VALIDATE_FAILED);
        }
        if (dto.getPageNum() == 0){
            ApiAssert.fail("无效页码");
        }
        List<ReturnOrder> returnOrders=returnOrderService.findList(dto);
        return CommonResult.success(CommonPage.restPage(returnOrders));
    }

    @ApiOperation(value = "退款分页查询，根据type区分")
    @GetMapping("/getFindAll")
    public CommonResult<CommonPage<ReturnOrder>>getFindAll(ReOrderDto dto){
        if (dto.getPageNum() == null || dto.getPageSize() == null){
            ApiAssert.fail(ResultCode.VALIDATE_FAILED);
        }
        if (dto.getPageNum() == 0){
            ApiAssert.fail("无效页码");
        }
        List<ReturnOrder> returnCauseList=returnOrderService.findListAll(dto);
        return CommonResult.success(CommonPage.restPage(returnCauseList));
    }

    @ApiOperation(value = "退款筛选查询。根据type分类")
    @GetMapping("/getFindMs")
    public CommonResult<CommonPage<ReturnOrder>>getListMs(ReOrderDto dto){
        if (dto.getPageNum() == null || dto.getPageSize() == null){
            ApiAssert.fail(ResultCode.VALIDATE_FAILED);
        }
        if (dto.getPageNum() == 0){
            ApiAssert.fail("无效页码");
        }
        List<ReturnOrder> returnOrders=returnOrderService.findListMs(dto);
        return CommonResult.success(CommonPage.restPage(returnOrders));
    }

    @ApiOperation(value = "查询记录")
    @GetMapping("/getAllObj")
    public CommonResult<Integer> getAllObj(Integer status){
        int aa=returnOrderService.getAllObj(status);
        return CommonResult.success(aa);
    }

    @ApiOperation(value = "查询记录2")
    @GetMapping("/getAllObjTwo")
    public CommonResult<Integer> getAllObjTwo(Integer status){
        int bb=returnOrderService.getAllObjTwo(status);
        return CommonResult.success(bb);
    }

    @ApiOperation(value = "根据是否已拒绝软删除")
    @DeleteMapping("/getAllDel")
    public CommonResult<ReturnOrder> getAllDel(GoodReturnVo vo){
        int success=returnOrderService.deletes(vo);
        return success==1?CommonResult.success():CommonResult.failed();
    }

    @ApiOperation(value = "根据id修改状态")
    @PostMapping("/getUpdateStatus")
    public CommonResult<ReturnOrder> getUpdateStatus(GoodReturnVo vo){
        int success=returnOrderService.updateStatus(vo);
        return success==1?CommonResult.success():CommonResult.failed();
    }

    @ApiOperation(value = "根据id修改状态2")
    @PostMapping("/getUpdateStatusTwo")
    public CommonResult<ReturnOrder> getUpdateStatusTwo(GoodReturnVo vo){
        int success=returnOrderService.updateStatus2(vo);
        return success==1?CommonResult.success():CommonResult.failed();
    }
}

